﻿using System;
using System.Web;
using SocialShare.BusinessLogicLayer;
using SocialShare.BusinessEntities;
using SocialShare.BLL;
using System.Configuration;
using SocialShare.DAL.Facades;

public partial class Admin_change_password : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void lnbSave_Click(object sender, EventArgs e)
    {
        ConfigReader configReader = new ConfigReader();

        if(HttpContext.Current.Request.Cookies["AdminId"]==null)
        {
            Response.Redirect("~/admin-login.aspx");
        }

        Int32 userId = Convert.ToInt32(HttpContext.Current.Request.Cookies["AdminId"].Value);
        MemberFacade bll = new MemberFacade();
        SocialShare_Admin_Users user = bll.GetAdmin_UsersByAdmin_User_Id(userId);

        if (user.Password == txtOldPassword.Text.Trim())
        {
            user.Password = txtNewPassword.Text.Trim();
            bll.UpdateAdmin_Users(user);

            divMessage.Visible = true;
            divMessage.Attributes.Add("class", "success");
            lblMessage.Text = configReader.ReadConfigurationValue(ConfigurationManager.AppSettings[APP_SETTINGS_NAME.MessageLocation.ToString()], SITE_MESSAGES.PASSWORD_CHANGE_SUCCESS.ToString());

            txtNewPassword.Text = string.Empty;
            txtOldPassword.Text = string.Empty;
            txtRetype.Text = string.Empty;
        }
        else
        {
            divMessage.Visible = true;
            divMessage.Attributes.Add("class", "error");
            lblMessage.Text = configReader.ReadConfigurationValue(ConfigurationManager.AppSettings[APP_SETTINGS_NAME.MessageLocation.ToString()], SITE_MESSAGES.PASSWORD_NOT_MATCHED.ToString());
        }
    }
}